<template>
  <div class="app-container">
    <div class="top_filter">
      <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="110px">
        <el-form-item label="回款编号" prop="code">
          <el-input
            v-model="queryParams.code"
            placeholder="请输入回款编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="结算单编号" prop="statementCode">
          <el-input
            v-model="queryParams.statementCode"
            placeholder="请输入结算单编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="发票号码" prop="invoiceCode">
          <el-input
            v-model="queryParams.invoiceCode"
            placeholder="请输入发票号码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="开票状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择开票状态" clearable filterable>
            <el-option
              v-for="item in invoicingStatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="撤销状态" prop="cancelStatus">
          <el-select v-model="queryParams.cancelStatus" placeholder="请选择撤销状态" clearable filterable>
            <el-option
              v-for="item in cancelStatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="回款时间" prop="returnTimeList">
          <el-date-picker
            v-model="queryParams.returnTimeList"
            type="daterange"
            range-separator="至"
            value-format="yyyy-MM-dd"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery('queryForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="info"-->
    <!--          plain-->
    <!--          icon="el-icon-download"-->
    <!--          size="mini"-->
    <!--          @click="handleExport"-->
    <!--          v-hasPermi="['statementReturnRecord:statementReturnRecord:export']"-->
    <!--        >导出回款记录-->
    <!--        </el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="primary"-->
    <!--          plain-->
    <!--          icon="el-icon-upload2"-->
    <!--          size="mini"-->
    <!--          @click="handleImport"-->
    <!--          v-hasPermi="['statementReturnRecord:statementReturnRecord:import']"-->
    <!--        >批量导入回款-->
    <!--        </el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="danger"-->
    <!--          :disabled="multiple"-->
    <!--          plain-->
    <!--          icon="el-icon-delete"-->
    <!--          size="mini"-->
    <!--          @click="handleCancel"-->
    <!--          v-hasPermi="['statementReturnRecord:statementReturnRecord:cancel']"-->
    <!--        >批量撤销记录-->
    <!--        </el-button>-->
    <!--      </el-col>-->
    <!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    <!--    </el-row>-->
    <el-table v-loading="loading" :data="statementReturnRecordList" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center" width="50" />
      <el-table-column label="回款编号" align="center" prop="code" />
      <el-table-column label="结算单编号" align="center" prop="statementCode" />
      <el-table-column label="发票号码" align="center" prop="invoiceCode">
        <template slot-scope="scope">
          <el-link type="primary" @click="handleViewInvoice(scope.row)">{{ scope.row.invoiceCode }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="回款金额(元)" align="center" prop="returnAmount" />
      <el-table-column label="回款时间" align="center" prop="returnTime">
        <template slot-scope="scope">
          <span>{{ parseTimeNew(scope.row.returnTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="登记人员" align="center" prop="createBy" />-->
      <el-table-column label="开票状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status === '0'">未开票</span>
          <span v-if="scope.row.status === '1'">已开票</span>
          <span v-if="scope.row.status === '2'">部分已开票</span>
          <span v-if="scope.row.status === '3'">无需开票</span>
        </template>
      </el-table-column>
      <el-table-column label="撤销状态" align="center" prop="cancelStatus">
        <template slot-scope="scope">
          <span v-if="scope.row.cancelStatus === '0'">正常</span>
          <span v-if="scope.row.cancelStatus === '1'">已撤销</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="撤销原因" align="center" prop="cancelReason" :show-overflow-tooltip="true">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ scope.row.cancelReason }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ scope.row.remark }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作时间" align="center" prop="updateTime">
        <template slot-scope="scope">
          <span v-if="scope.row.updateTime != null">{{ parseTimeNew(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          <span v-if="scope.row.updateTime == null">{{ parseTimeNew(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-edit"-->
      <!--            @click="handleUpdate(scope.row)"-->
      <!--            v-hasPermi="['statementReturnRecord:statementReturnRecord:edit']"-->
      <!--          >修改-->
      <!--          </el-button>-->
      <!--          &lt;!&ndash;          <el-button&ndash;&gt;-->
      <!--          &lt;!&ndash;            size="mini"&ndash;&gt;-->
      <!--          &lt;!&ndash;            type="text"&ndash;&gt;-->
      <!--          &lt;!&ndash;            icon="el-icon-delete"&ndash;&gt;-->
      <!--          &lt;!&ndash;            @click="handleDelete(scope.row)"&ndash;&gt;-->
      <!--          &lt;!&ndash;            v-hasPermi="['statementReturnRecord:statementReturnRecord:remove']"&ndash;&gt;-->
      <!--          &lt;!&ndash;          >删除&ndash;&gt;-->
      <!--          &lt;!&ndash;          </el-button>&ndash;&gt;-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-delete"-->
      <!--            v-if="!(scope.row.cancelStatus === '1'|| scope.row.status === '1')"-->
      <!--            @click="handleCancel(scope.row)"-->
      <!--            v-hasPermi="['statementReturnRecord:statementReturnRecord:cancel']"-->
      <!--          >撤销-->
      <!--          </el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>

    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        :current-page="queryParams.pageNum"
        :page-sizes="pageSizes"
        :page-size="queryParams.pageSize"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>

    <!-- 添加或修改结算单回款记录对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>-->
<!--      <el-form ref="form" :model="form" :rules="rules" label-width="120px">-->
<!--        <el-form-item label="结算单编号" prop="statementCode">-->
<!--          <el-input v-model="form.statementCode" placeholder="请输入结算单编号" :disabled="true" />-->
<!--        </el-form-item>-->
<!--        &lt;!&ndash;        <el-form-item label="客户企业(二级)" prop="companyId">&ndash;&gt;-->
<!--        &lt;!&ndash;          <el-select v-model="form.companyId" placeholder="请选择客户企业" clearable filterable >&ndash;&gt;-->
<!--        &lt;!&ndash;            <el-option&ndash;&gt;-->
<!--        &lt;!&ndash;              v-for="item in allCompanyList"&ndash;&gt;-->
<!--        &lt;!&ndash;              :key="item.id"&ndash;&gt;-->
<!--        &lt;!&ndash;              :label="item.nameSecond"&ndash;&gt;-->
<!--        &lt;!&ndash;              :value="item.id"&ndash;&gt;-->
<!--        &lt;!&ndash;            />&ndash;&gt;-->
<!--        &lt;!&ndash;          </el-select>&ndash;&gt;-->
<!--        &lt;!&ndash;        </el-form-item>&ndash;&gt;-->
<!--        <el-form-item label="发票号码" prop="invoiceCode">-->
<!--          <el-input v-model="form.invoiceCode" placeholder="发票号码" />-->
<!--        </el-form-item>-->
<!--        &lt;!&ndash;        <el-form-item label="回款金额(元)" prop="returnAmount">&ndash;&gt;-->
<!--        &lt;!&ndash;          <el-input v-model="form.returnAmount" placeholder="请输入回款金额" />&ndash;&gt;-->
<!--        &lt;!&ndash;        </el-form-item>&ndash;&gt;-->
<!--        &lt;!&ndash;        <el-form-item label="回款时间" prop="returnTime" >&ndash;&gt;-->
<!--        &lt;!&ndash;          <el-date-picker clearable&ndash;&gt;-->
<!--        &lt;!&ndash;            v-model="form.returnTime"&ndash;&gt;-->
<!--        &lt;!&ndash;            type="datetime"&ndash;&gt;-->
<!--        &lt;!&ndash;            style="width: 360px"&ndash;&gt;-->
<!--        &lt;!&ndash;            value-format="yyyy-MM-dd HH:mm:ss"&ndash;&gt;-->
<!--        &lt;!&ndash;            placeholder="请选择回款时间">&ndash;&gt;-->
<!--        &lt;!&ndash;          </el-date-picker>&ndash;&gt;-->
<!--        &lt;!&ndash;        </el-form-item>&ndash;&gt;-->
<!--        <el-form-item label="备注" prop="remark">-->
<!--          <el-input-->
<!--            v-model="form.remark"-->
<!--            type="textarea"-->
<!--            placeholder="请输入内容"-->
<!--            maxlength="255"-->
<!--            show-word-limit-->
<!--          />-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--        <el-button @click="cancel">取 消</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->

    <!-- 回款记录导入对话框 -->

    <!-- 撤销回款记录对话框 -->

  </div>
</template>

<script>
import {
  listStatementReturnRecord
  // getStatementReturnRecord,
  // delStatementReturnRecord,
  // addStatementReturnRecord,
  // updateStatementReturnRecord,
  // cancelStatementReturnRecord
} from '@/api/statement'
import { parseTime } from '@/utils'

export default {
  name: 'ReturnRecord',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 结算单回款记录表格数据
      statementReturnRecordList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        orderByColumn: 'm.create_time',
        isAsc: 'desc',
        id: null,
        code: null,
        pageNum: 1,
        pageSize: 10,
        statementId: null,
        companyId: null,
        invoiceId: null,
        returnAmount: null,
        returnTime: null,
        status: null,
        statementCode: null,
        companyNameSecond: null,
        invoiceCode: null,
        returnTimeList: null,
        cancelStatus: null,
        createBy: null
      },
      // 表单参数
      form: {},
      // 表单校验
      // rules: {
      //   statementCode: [{required: true, trigger: 'blur', message: '请输入结算单编号'}],
      //   returnTime: [{required: true, trigger: 'blur', message: '请选择回款时间'}],
      //   returnAmount: [{required: true, trigger: 'blur', message: '请输入回款金额'}],
      // },
      // 回款记录导入参数

      // 开票状态
      invoicingStatusList: [
        { value: '0', label: '未开票' },
        { value: '1', label: '已开票' }
      ],
      // 撤销状态
      cancelStatusList: [
        { value: '0', label: '正常' },
        { value: '1', label: '已撤销' }
      ],
      // 每页条数
      pageSizes: [10, 20, 50]
    }
  },
  created() {
    if (this.$route.query.id) {
      this.queryParams.statementId = this.$route.query.id
    }
    this.getList()
  },
  methods: {
    /** 查询结算单回款记录列表 */
    getList() {
      // set时间段查询条件
      if (this.queryParams.returnTimeList) {
        this.queryParams.returnTimeStart = this.queryParams.returnTimeList[0]
        this.queryParams.returnTimeEnd = this.queryParams.returnTimeList[1]
      } else {
        this.queryParams.returnTimeStart = null
        this.queryParams.returnTimeEnd = null
      }
      this.loading = true
      listStatementReturnRecord(this.queryParams).then(response => {
        this.statementReturnRecordList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    // 取消按钮
    // cancel() {
    //   this.open = false
    //   this.reset()
    // },
    // 表单重置
    // reset() {
    //   this.form = {
    //     id: null,
    //     statementId: null,
    //     companyId: null,
    //     invoiceId: null,
    //     returnAmount: null,
    //     returnTime: null,
    //     status: null,
    //     createBy: null,
    //     createTime: null,
    //     updateBy: null,
    //     updateTime: null,
    //     remark: null,
    //     statementCode: null,
    //     companyNameSecond: null,
    //     invoiceCode: null
    //   }
    //   this.resetForm('form')
    // },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery(formName) {
      this.$refs[formName].resetFields()
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */

    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset()
    //   const id = row.id || this.ids
    //   getStatementReturnRecord(id).then(response => {
    //     this.form = response.data
    //     this.open = true
    //     this.title = '修改结算单回款'
    //   })
    // },
    /** 提交按钮 */

    /** 删除按钮操作 */

    /** 撤销按钮操作 */

    /** 撤销回款表单 提交 */

    /** 撤销回款表单 取消*/

    /** 导出按钮操作 */
    // handleExport() {
    //   this.download('statementReturnRecord/statementReturnRecord/export', {
    //     ...this.queryParams
    //   }, `statementReturnRecord_${new Date().getTime()}.xlsx`)
    // },
    /** 导入按钮操作 */

    /** 下载模板操作 */

    // 文件上传中处理

    // 文件上传成功处理

    // 提交上传文件

    handleViewInvoice(row) {
      // 需要传的数据
      const data = row.invoiceCode
      // 路由跳转到新页面
      this.$router.push({ // 核心语句
        path: '/statement/Invoice', // 跳转的路径
        query: { // 路由传参时push和query搭配使用 ，作用时传递参数
          number: data
        }
      })
    },
    // 每页条数改变
    handleSizeChange(val) {
      this.queryParams.pageSize = val
      this.getList()
    },

    // 当前页改变
    handleCurrentChange(val) {
      this.queryParams.pageNum = val
      this.getList()
    },
    /** 时间转换 */
    parseTimeNew(val) {
      return parseTime(val)
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  padding: 20px;
  line-height: 1;

  .top_filter {
    margin-bottom: 20px;
  }

  .pagination {
    margin-top: 20px;
    display: flex;
    justify-content: center;
  }
}
</style>
